; M0DGQ ; ATU RX ; TEST TWO INDEPENDENT VARIBLES ARE RECEIVED ; AND OUTPUT ON SHIFT REGISTERS/ 4-16 LINE DECODERS ; CLEAR SHIFT REGISTER START UP HASH ;********************************************************************************** LIST p=16F628A ;tell assembler what chip we are using INCLUDE "P16F628A.inc" ;include the defaults for the chip __CONFIG 0x3F18 ;sets the configuration settings ;INT 4mhZ OSC ;*************************************************************************** CBLOCK 0x20 ; Declare variable addresses starting at 0x20 BIT_COUNT1 BIT_COUNT2 COUNT_0 TEMP VAR_2 VAR_1 BYTE_1 BYTE_2 COMPARE ENDC ;***************************************************************** ORG 0x000 ; Program start GOTO START ;****************************************************************** #DEFINE SDATA PORTB,3 ;MAKE OUTPUT #DEFINE CLOCK PORTB,4 ;MAKE OUTPUT #DEFINE LATCH_1 PORTB,0 ;MAKE OUTPUT #DEFINE LATCH_2 PORTB,5 ;MAKE OUTPUT ;************************************************************************** START ; INITIALIZE PORTS MOVLW 7 MOVWF CMCON ; CMCON=7 set comperators off BANKSEL TRISA ;SELECT BANK1 MOVLW b'00000000' ;SET PORTA, ALL OUTPUTS MOVWF TRISA ; MOVLW b'00000010' ;SET PORTB, BITS 0,AND 1 ARE INPUTS MOVWF TRISB ; SET BAUD RATE = 9600, No Parity, 1 Stop Bit MOVLW 0x19 ; 0x19=9600 bps (0x0C=19200 bps) MOVWF SPBRG MOVLW b'00100100' ; brgh = high (2) MOVWF TXSTA ; ENABLE ASYNC TX, set brgh BANKSEL PORTA ;BACK TO BANK0 MOVLW b'10010000' ; ENABLE ASYNC RX MOVWF RCSTA ;************************************************************ ; PROVIDE SETTLE TIME FOR START UP CLRF COUNT_0 ; THIS CREATES A 500uS (APPROX) DELAY WAIT DECFSZ COUNT_0,F GOTO WAIT MOVF RCREG,W ; FLUSH RECEIVE BUFFER MOVF RCREG,W ; FLUSH RECEIVE BUFFER MOVF RCREG,W ; FLUSH RECEIVE BUFFER CLRF VAR_1 ; CLEAR VARIABLES/SHIFT REGISTER START UP HASH CLRF VAR_2 CALL SERIAL_1 ; SEND CLEARED SERIAL DATA TO SHIFT REGISTER 1 CALL SERIAL_2 ; SEND CLEARED SERIAL DATA TO SHIFT REGISTER 2 ;************************************************************ ; MAIN LOOP LOOP CALL RECEIVE ; WAIT FOR A DATA BYTE CALL SERIAL_1 ;SEND SERIAL VAR_1 CALL SERIAL_2 ;SEND SERIAL VAR_2 GOTO LOOP ;************************************************************************* ; RECEIVE BYTE FROM RS232 AND STORE IN VAR_1 AND VAR_2 RECEIVE BTFSS PIR1,RCIF ; CHECK FOR RECEIVED DATA GOTO R1 MOVF RCREG,W ; MOVE RECEIVED DATA BYTE TO TEMP MOVWF TEMP MOVWF COMPARE MOVLW b'11111111' ;LOAD COMPARISON RS232 BYTE XORWF COMPARE,W BTFSS STATUS,Z ;ARE THEY THE SAME? GOTO BRANCH ;NO,BRANCH AROUND AND SEND DATA TO SHIFT REGISTERS MOVLW b'11111111' ;RECEIVED BYTE=LINK TEST BYTE SO SEND BACK TO TX FOR LINK VARIFICATION MOVWF TXREG ; SEND L DATA IN W BANKSEL TRISA ; RAM PAGE 1 BTFSS TXSTA,TRMT ; HAS TX FINISHED? GOTO $-1 ;NO, GO BACK AND WAIT FOR TXSTA,TRMT BIT TO SET HIGH BANKSEL PORTA ; TX FINISHED SO BACK TO RAM PAGE 0 GOTO R1 BRANCH BTFSS TEMP,7 ; SAVE DATA BYTE IN VAR_1 OR VAR_2 DEPENDING ON STATUS OF BIT 7 IN DATA BYTE GOTO $+4 ; BIT 7 NOT SET SO GO SAVE BYTE IN VAR_1 MOVFW TEMP ; BIT 7 SET SO SAVE BYTE IN IN VAR_2 MOVWF VAR_2 GOTO $+3 MOVFW TEMP MOVWF VAR_1 R1 RETURN ;********************************************************************* ;8 BIT SERIAL SEND ROUTINE SERIAL SERIAL_1 MOVLW .8 ;SET BIT_COUNT1 FOR 8 BITS MOVWF BIT_COUNT1 ; MOVF VAR_1,W ;MOVE VAR_HI INTO BYTE_1 MOVWF BYTE_1 ; BCF STATUS,C ;CLEAR CARRY ETC LOOP1 RLF BYTE_1,F ;ROTATE BYTE_1 LEFT BY ONE BIT BTFSS STATUS,C ;DOES CARRY = 1? BCF SDATA ;NO,SET SDATA TO 0 BTFSC STATUS,C ;DOES CARRY= 0? BSF SDATA ;NO, SO SET SDATA TO 1 BSF CLOCK ;GENERATE ONE CLOCK NOP ;SETTLE TIME BCF CLOCK ;CLEAR CLOCK DECFSZ BIT_COUNT1 ;HAVE ALL BITS OF BYTE 1 BEEN SENT? GOTO LOOP1 ;IF NOT REPEAT BSF LATCH_1 ;SET LATCH_1 NOP ;SETTLE TIME BCF LATCH_1 ;CLEAR LATCH RETURN ;************************************************************************************************************* ;8 BIT SERIAL SEND ROUTINE SERIAL SERIAL_2 MOVLW .8 ;SET BIT_COUNT2 FOR 8 BITS MOVWF BIT_COUNT2 ; MOVF VAR_2,W ;MOVE VAR_2 INTO BYTE_2 MOST SIGNIFICANT BYTE LOADED MOVWF BYTE_2 ; BCF STATUS,C ;CLEAR CARRY ETC LOOP2 RLF BYTE_2,F ;ROTATE BYTE_2 LEFT BY ONE BIT BTFSS STATUS,C ;DOES CARRY = 1? BCF SDATA ;NO,SET SDATA TO 0 BTFSC STATUS,C ;DOES CARRY= 0? BSF SDATA ;NO, SO SET SDATA TO 1 BSF CLOCK ;GENERATE ONE CLOCK NOP ;SETTLE TIME BCF CLOCK ;CLEAR CLOCK DECFSZ BIT_COUNT2 ;HAVE ALL BITS OF BYTE 2 BEEN SENT? GOTO LOOP2 ;IF NOT REPEAT BSF LATCH_2 ;SET LATCH_2 NOP ;SETTLE TIME BCF LATCH_2 ;CLEAR LATCH RETURN ;************************************************************************************************* END ;***********************************************************************************************